package com.briup.common.util;

import lombok.Data;

import java.util.Date;

/**
 * @Description: TODO
 * @Author: GX Cui
 * @Date 下午2:35 2022/11/18
 */
@Data
public class Result<T> {

    private Integer code;

    private String message;

    private Integer count;

    private T rsp;

    private long time;

    // 补充一个空参构造器
    public Result(){}

    private Result(Integer code, String message, Integer count, T rsp){
        this.code = code;
        this.message = message;
        this.count = count;
        this.rsp = rsp;
        this.time = new Date().getTime();
    }

    public static <T> Result<T> success(String message, T rsp, Integer count) {
        return new Result<T>(200,message,count,rsp);
    }

    public static <T> Result<T> success(T rsp, Integer count) {
        return success("成功", rsp, count);
    }

    public static <T> Result<T> recordEmpty() {
        return fail(-404, "数据为空");
    }

    public static <T> Result<T> fail() {
        return fail("失败");
    }

    public static <T> Result<T> fail(String message) {
        return fail(-1, message);
    }

    public static <T> Result<T> fail(Integer code, String message) {
        return new Result<T>(code,message,0,null);
    }

    public static <T> Result<T> fail(CodeStatus codeStatus) {
        return fail(codeStatus.getCode(),codeStatus.getMsg());
    }

}
